/*********************************************************
          File Name:10.11.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Tue 15 Sep 2015 03:04:41 PM CST
**********************************************************/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using std::cout; using std::endl; using std::vector; using std::sort;
using std::stable_sort; using std::string;

void show(vector<string> v)
{
        for(const auto &x: v)
                cout << x << " ";
        cout << endl;
}

void show(vector<int> v)
{
        for(const auto &x: v)
                cout << x << " ";
        cout << endl;
}

bool predicate_s(const string &s1, const string &s2)
{
        return (s1 > s2 ? true : false);
}

bool predicate_i(const int &a, const int &b)
{
        return (a > b ? true : false);
}

auto using_sort(vector<string> &v) -> vector<string>
{
        vector<string> tmp(v);
        sort(tmp.begin(), tmp.end(), predicate_s);

        return tmp;
}

auto using_sort(vector<int> &v) -> vector<int>
{
        vector<int> tmp(v);
        sort(tmp.begin(), tmp.end(), predicate_i);

        return tmp;
}

auto using_stable_sort(vector<string> &v) -> vector<string>
{
        vector<string> tmp(v);

        stable_sort(tmp.begin(), tmp.end(), predicate_s);

        return tmp;
}

auto using_stable_sort(vector<int> &v) -> vector<int>
{
        vector<int> tmp(v);

        stable_sort(tmp.begin(), tmp.end(), predicate_i);

        return tmp;
}

int main()
{
        vector<string> vs{"this", "is", "a", "test"};

        show(vs);
        show(using_sort(vs));
        show(using_stable_sort(vs));

        cout << "\e[35mvector<int> \e[0m\n";

        vector<int> vi{92, 89, 309};

        show(vi);
        show(using_sort(vi));
        show(using_stable_sort(vi));

        return 0;
}
